package com.example.rocketdemo.api;

import com.example.rocketdemo.dmain.LogMessageVo;
import com.example.rocketdemo.producer.LogProducer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author GuoAo
 * @className LogController
 * @date 2025/7/16
 * @description TODO
 */
@RequestMapping("/log")
@RestController
@Slf4j
@RequiredArgsConstructor
public class LogController {
    private final LogProducer logProducer;

    @PostMapping("/key")
    public void logKey(@RequestBody LogMessageVo  message) {
        log.info("接收的消息：{}",message);
        logProducer.send(message.getTopic(),message.getTag(),message.getMessage());
    }

    @PostMapping("/log-tx")
    public String logTx(@RequestBody LogMessageVo  message){
        log.info("发送事务消息：{}",message);
        logProducer.sendTxMsg(message.getTopic(),message.getTag(),message.getMessage());
        return "success";
    }
}
